<template>
  <div class="components-input-demo-presuffix">
    <!---->
    <a-input @click="openModal" placeholder="请点击选择居民用户" v-model="name" readOnly :disabled="disabled">
      <a-icon slot="prefix" type="cluster" title="居民用户选择控件" />
      <a-icon v-if="jianKangXinXiId" slot="suffix" type="close-circle" @click="handleEmpty" title="清空" />
    </a-input>

    <j-select-inFo-modal
      ref="innerDepartSelectModal"
      :modal-width="modalWidth"
      :multi="multi"
      :rootOpened="rootOpened"
      :depart-id="jianKangXinXiId"
      @ok="handleOK"
      @initComp="initComp"
    />
  </div>
</template>

<script>
import JSelectInFoModal from './modal/JSelectInFoModal'
export default {
  name: 'JSelectInFo',
  components: {
    JSelectInFoModal
  },
  props: {
    value: {
      type: String,
      default: '',
      required: false
    },
    modalWidth: {
      type: Number,
      default: 1200,
      required: false
    },
    msg: {
      type: Object,
      required: false
    },
    multi: {
      type: Boolean,
      default: false,
      required: false
    },
    rootOpened: {
      type: Boolean,
      default: true,
      required: false
    },

    disabled: {
      type: Boolean,
      required: false,
      default: false
    },
    // 自定义返回字段，默认返回 id
    customReturnField: {
      type: String,
      default: 'id'
    }
  },
  data() {
    return {
      visible: false,
      confirmLoading: false,
      jianKangXinXiId: '',
      name: ''
    }
  },
  mounted() {
    this.jianKangXinXiId = this.msg
  },
  watch: {
    msg(val) {
      this.jianKangXinXiId = val.id
      this.name = val.name
    }
  },
  created() {
    this.$nextTick(() => {
      if (this.$route.query.yongHuBiaoShi) {
        if (localStorage.getItem('jiangkangInfo')) {
          let row = JSON.parse(localStorage.getItem('jiangkangInfo'))
          console.log(row)
          this.jianKangXinXiId = row.id
          this.name = row.xingMing
        }
      } else {
        let val = this.msg
        this.jianKangXinXiId = val.id
        this.name = val.name
      }
    })
  },
  methods: {
    initComp(jianKangXinXiId) {
      this.jianKangXinXiId = jianKangXinXiId
    },
    openModal() {
      if (this.$route.query.yongHuBiaoShi) {
      } else {
        this.$refs.innerDepartSelectModal.show()
      }
    },
    handleOK(val) {
      debugger
      this.jianKangXinXiId = val.id
      this.name = val.xingMing
      this.$emit('change', val.id)
      this.$emit('addChange', val)
    },
    getjianKangXinXiId() {
      return this.jianKangXinXiId
    },
    handleEmpty() {
      this.handleOK('')
    }
  },
  model: {
    prop: 'value',
    event: 'change'
  }
}
</script>

<style scoped>
.components-input-demo-presuffix .anticon-close-circle {
  cursor: pointer;
  color: #ccc;
  transition: color 0.3s;
  font-size: 12px;
}
.components-input-demo-presuffix .anticon-close-circle:hover {
  color: #f5222d;
}
.components-input-demo-presuffix .anticon-close-circle:active {
  color: #666;
}
</style>
